//
//  ZQMyAdressTableViewCell.m
//  jianzhik
//
//  Created by huami on 2018/8/29.
//  Copyright © 2018年 WKWebView. All rights reserved.
//

#import "ZQMyAdressTableViewCell.h"
#import "ZQAFHelper.h"
#import "ZQ_GetCurrentViewNavTool.h"
@implementation ZQMyAdressTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
- (IBAction)deleteBtnClick:(UIButton *)sender {
    UIAlertController * alert = [UIAlertController
                                 alertControllerWithTitle:@"温馨提示"
                                 message:@"是否删除地址"
                                 preferredStyle:UIAlertControllerStyleAlert];
    
    UIAlertAction* yesButton = [UIAlertAction
                                actionWithTitle:@"确认"
                                style:UIAlertActionStyleDestructive
                                handler:^(UIAlertAction * action) {
                                    NSLog(@"提交后%@",alert.textFields.lastObject.text);
                                    [self deleteModel];
                                    //                                    [self changeKGF:alert];
                                    
                                }];
    
    UIAlertAction* noButton = [UIAlertAction
                               actionWithTitle:@"取消"
                               style:UIAlertActionStyleDefault
                               handler:^(UIAlertAction * action) {
                                   //Handle no, thanks button
                               }];
    
    //    [alert addTextFieldWithConfigurationHandler:^(UITextField *textField) {
    //        textField.placeholder = @"请在此输入矿工费数值";
    //    }];
    
    [alert addAction:yesButton];
    [alert addAction:noButton];
    [[ZQ_GetCurrentViewNavTool viewControllerSupportView:self] presentViewController:alert animated:YES completion:nil];
}

- (void)deleteModel
{
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    parameters[@"Id"] = self.model.Id;
    [ZQAFHelper afnetworkRequestWithPostURL:@"/v1/user/deladdress" parameters:parameters view:[ZQ_GetCurrentViewNavTool viewControllerSupportView:self].view finishedBlcok:^(NSDictionary *dict) {
        NSLog(@"mdoel == %@",self.model);
        SendNotify(@"deleteAddress", nil, @{@"model": self.model});

        [UIHelper showSuccessMessage:@"删除成功" afterHideHud:2 toView:[ZQ_GetCurrentViewNavTool viewControllerSupportView:self].view completion:nil];
    }];
}

- (void)setModel:(ZQAdressModels *)model
{
    _model = model;
    self.bTypeLabel.text =  model.Symbol;
    self.balanceLabel.text = [NSString stringWithFormat:@"当前余额：%@",model.Amount];
    self.addressModel.text = model.Address;
}
@end
